package com.bw.zg3.Cate.New

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView
import com.bw.base.entity.NewEntityResultItem
import com.bw.zg3.R
import com.bw.zg3.databinding.N1Binding
import com.chad.library.adapter.base.BaseQuickAdapter

class NewApter: PagingDataAdapter<NewEntityResultItem,NewApter.NewViewHolder>(New) {
    private var mOnItemClickListener: OnItemClickListener? = null
    private var mOnItemLongClickListener: OnItemLongClickListener? = null
    companion object{
        val New= object : ItemCallback<NewEntityResultItem>() {
            override fun areItemsTheSame(
                oldItem: NewEntityResultItem,
                newItem: NewEntityResultItem,
            ): Boolean {
                return oldItem==newItem
            }

            override fun areContentsTheSame(
                oldItem: NewEntityResultItem,
                newItem: NewEntityResultItem,
            ): Boolean {
                return oldItem.id==newItem.id
            }

        }
    }
    class NewViewHolder(view: View): RecyclerView.ViewHolder(view){
       val binding=DataBindingUtil.bind<N1Binding>(view)
    }
    override fun onBindViewHolder(holder: NewViewHolder, position: Int) {
            holder.binding?.new1=getItem(position)
        val item = getItem(position)
        holder.binding?.new1=item
        holder.itemView.setOnClickListener {
            this.mOnItemClickListener?.onItemClick(position,item!!)
        }
        holder.itemView.setOnLongClickListener {
            this.mOnItemLongClickListener?.onItemLongClick(item!!)
            return@setOnLongClickListener true
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NewViewHolder {
        val inflate = LayoutInflater.from(parent.context).inflate(R.layout.n1, parent, false)
        return NewViewHolder(inflate)
    }

    fun setOnItemClickListener(listener: OnItemClickListener?) {

       this. mOnItemClickListener=listener

    }

    fun setOnItemLongClickListener(listener: OnItemLongClickListener?) {
        this. mOnItemLongClickListener=listener
    }

}

interface OnItemClickListener {

    fun onItemClick(position: Int,item: NewEntityResultItem)
}
interface OnItemLongClickListener {

    fun onItemLongClick(item: NewEntityResultItem): Boolean
}

